#!/usr/bin/python
# coding:gbk
#Filename:pathmapper.py
from __future__ import unicode_literals
import os
import sys

source = os.path.realpath(sys.argv[1])
target = os.path.realpath(sys.argv[2])

def isdir(x):
    return os.path.isdir(x) and x != '.svn'

def mkfloders(src,tar):
    paths = os.listdir(src)
    paths = map(lambda name:os.path.join(src,name),paths)
    paths = filter(isdir, paths)
    if(len(paths)<=0):
        return
    for i in paths:
        (filepath, filename)=os.path.split(i)
        targetpath = os.path.join(tar,filename)
        not os.path.isdir(targetpath) and os.mkdir(targetpath)
        mkfloders(i,targetpath)

def copyfloders(source, target):
    if(os.path.isdir(source)):
        if(target.find(source) == 0):
            print("can not generate new folder in source folder")
        else:
            if not os.path.isdir(target):
                os.mkdir(target)
            mkfloders(source,target)
    else:
        print("source floder must exists")

